home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 351-375 / disk_351 / pdc / libsrc.lzh / LibSrc / StdIO / gets.c < prev    next >
C/C++ Source or Header  |  1990-04-07  |  2KB  |  47 lines

  1. /*
  2.  * Libraries and headers for PDC release 3.3 (C) 1989 Lionel Hummel.
  3.  * PDC Software Distribution (C) 1989 Lionel Hummel and Paul Petersen.
  4.  * PDC I/O Library (C) 1987 by J.A. Lydiatt.
  5.  *
  6.  * This code is freely redistributable upon the conditions that this 
  7.  * notice remains intact and that modified versions of this file not
  8.  * be included as part of the PDC Software Distribution without the
  9.  * express consent of the copyright holders.  No warrantee of any
  10.  * kind is provided with this code.  For further information, contact:
  11.  *
  12.  *  PDC Software Distribution    Internet:                     BIX:
  13.  *  P.O. Box 4006             or hummel@cs.uiuc.edu            lhummel
  14.  *  Urbana, IL  61801-8801       petersen@uicsrd.csrd.uiuc.edu
  15.  */
  16.  
  17. /* gets.c - The ubiquitous gets() function, present solely for compatibility
  18.  *
  19.  *     gets()  Read from stdin to buffer until EOF or newline
  20.  *
  21.  * NOTE: This function is one big bug.  Since it doesn't hold any regard for
  22.  *       the size of the buffer it is copying into, the USER of a program
  23.  *       containing gets() can cause crashes and other security breaches by
  24.  *       typing past the end of your buffer.  It is provided here for
  25.  *       compatibility purposes only.  DO NOT USE THIS FUNCTION IN THE CODE
  26.  *       THAT YOU WRITE.  Although it is provided here in source form, it
  27.  *       is not present in PDC.lib.
  28.  */
  29.  
  30. #include <stdio.h>
  31.  
  32. char *gets( linbuf )
  33. char *linbuf;
  34. {
  35.     char *s;
  36.     int      c;
  37.  
  38.     s = &linbuf[0];
  39.     while ( (c = getchar()) != EOF && c != '\n' )
  40.         *s++ = c;
  41.  
  42.     *s = '\0';
  43.     if ( c == EOF && s == &linbuf[0] )
  44.         return NULL;
  45.     return (&linbuf[0]);
  46. }
  47.